package main

import (
	"basic/interface"
	"basic/struct"
	"fmt"
)

// 声明一种新的数据类型
type myint int

// 定义结构体
type Book struct {
	title   string
	author  string
	subject string
	book_id myint
}

/**
 * 购买宠物
 */
func purchase(pet _interface.Pet) {
	fmt.Printf("购买动物%s :%v \n", pet.GetName(), pet)
}

func kill(a interface{}) {
	fmt.Printf("屠杀动物%v \n", a)

	//类型判断
	pet, ok := a.(_interface.Pet)
	if ok {
		fmt.Printf("你忍心屠杀宠物吗？ %v \n", pet)

		child, ok1 := a.(_interface.PetChild)
		if ok1 {
			fmt.Printf("我也是 PetChild %v \n", child)
		}

	} else {
		fmt.Printf("来吧,老子烂命一条 %v \n", pet)
	}

}

func main() {
	var book Book
	book.title = "Go 语言"
	book.author = "www.runoob.com"
	book.subject = "Go 语言教程"
	book.book_id = 6495407
	fmt.Printf("book : %v \n", book)

	animal := _struct.Animal{"dog", 10, 10, 10}
	animal.SetAge(10)
	animal.SetName("Dog")
	animal.Height = 20

	fmt.Printf("animal : %v \n", animal)
	fmt.Println(animal)

	// 定义子类方式一
	cat := _struct.Cat{_struct.Animal{"猫", 10, 10, 10}, "white"}
	//cat := model.Cat{animal, "white"}
	cat.Eat("鱼")
	// 定义子类方式二
	var cat2 _struct.Cat
	cat2.Age = 10
	cat2.Name = "猫"
	cat2.Weight = 10
	cat2.Height = 10
	cat2.Color = "white"
	cat2.Eat("鱼")
	fmt.Println(cat2)

	dog := _struct.Dog{_struct.Animal{"Dog", 10, 10, 10}, 4}
	fmt.Println(dog)

	purchase(&cat2)
	//purchase(&dog)

	kill(&cat2)
	kill(&dog)

	//var a _struct.Cat
	//a = cat2.( _struct.Cat)
	//println(a)
}
